package com.fun.demo;


import java.util.Optional;

public class OptionalTest {
    public static void main(String[] args) {
        String str = "IF";
//        String ret = Optional.ofNullable(str).orElse("ELSE");
//        System.out.println(ret);

        System.out.println(Optional.of(str).orElse("ELSE"));

        System.out.println(Optional.empty().orElse("ELSE"));

//        String ret1 = Optional.ofNullable(str).orElseGet(() -> {
//            StringBuilder sb = new StringBuilder();
//            sb.append("A");
//            sb.append("A");
//            sb.append("A");
//            return sb.toString();
//        });
//        System.out.println(ret1);
//
//        String ret2 =Optional.ofNullable(str).orElseThrow(() -> new RuntimeException("测试抛出运行时异常"));
//        System.out.println(ret2);

    }
}

